package com.guochenglang.www.util;

import com.guochenglang.www.common.PatternCommon;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 判断数据是否合法工具类
 *
 * @author GuoChenglang
 */
public class PatternUtil {
    /**
     * 邮箱正则
     */
    private static final Pattern EMAIL_PATTERN = Pattern.compile(PatternCommon.EMAIL_PATTERN);
    /**
     * 手机号正则
     */
    private static final Pattern PHONE_PATTERN = Pattern.compile(PatternCommon.PHONE_PATTERN);

    /**
     * 判断邮箱是否合法
     *
     * @param email 判断的邮箱
     * @return 判断结果
     */
    public static boolean isRealEmail(String email) {
        Matcher matcher = EMAIL_PATTERN.matcher(email);
        return matcher.matches();
    }

    /**
     * 判断手机号是否合法
     *
     * @param phone 判断的手机号
     * @return 判断结果
     */
    public static boolean isPhone(String phone) {
        Matcher matcher = PHONE_PATTERN.matcher(phone);
        return matcher.matches();
    }
}
